#include <reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
sbit ENLED=P1^4;
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
code uint8 number[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xa7,0xa1,0x86,0x8e};
uint8 a[6];
uint32 num;
uint16 counter;

void refresh()
{
	static uint8 j = 0;
	switch(j)
    {
		case 0: ADDR0 = 0;ADDR1 = 0;ADDR2 = 0;j++;P0 = number[a[0]];break;
		case 1: ADDR0 = 1;ADDR1 = 0;ADDR2 = 0;j++;P0 = number[a[1]];break;
		case 2: ADDR0 = 0;ADDR1 = 1;ADDR2 = 0;j++;P0 = number[a[2]];break;
		case 3: ADDR0 = 1;ADDR1 = 1;ADDR2 = 0;j++;P0 = number[a[3]];break;
		case 4: ADDR0 = 0;ADDR1 = 0;ADDR2 = 1;j++;P0 = number[a[4]];break;
		case 5: ADDR0 = 1;ADDR1 = 0;ADDR2 = 1;j = 0;P0 = number[a[5]];break;
		default: break;
	}
}

void light_num()
{
	a[0] = num%10;
	a[1] = num/10%10;
	a[2] = num/100%10;
	a[3] = num/1000%10;
	a[4] = num/10000%10;
	a[5] = num/100000%10;
}

void init_timer1()
{
	TMOD|=0x10;//M0置1
	TMOD&=0xdf;//M1置0
	TR1=1;
	TH1=0XFC;
	TL1=0X67;
}

void init_int()
{
	EA=1;
	ET1=1;
}

void main()
{
	ENLED=0;ADDR3=1;
	init_timer1();
	init_int();
	while(1);
}

void led_show() interrupt 3 //中断标号        y(中断向量)=8*x(中断标号)+3;
{
	TH1=0XFC;
	TL1=0X67;
	counter++;
	if(1000==counter)
	{
		counter=0;
		num++;
		light_num();
	}
	refresh();
}
